#include "VolumeRenderPCH.h"
#include "Cube.h"

//**************************************************************************************************
//FUNCTION:
void CCube::initV()
{
	m_VAO = createVAO4Cube();
	//setScale({ 0.5f, 0.5f, 0.5f });
	rotateX(90.0f);
	rotateY(180.0f);

	std::shared_ptr<CInputManager> pInputManager = CInputManager::getOrCreateInstance();
	//remove camare movement.
	pInputManager->unregisterCursorCallbackFunc(0);
	pInputManager->unregisterMouseButtonCallbackFunc(0);

	pInputManager->registerMouseButtonCallbackFunc(std::bind(&CCube::__processMouseButtonRight, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
}

//**************************************************************************************************
//FUNCTION:
void CCube::updateV()
{
	if (m_ButtonRightPressed)
	{
		auto CurMousePos = CInputManager::getOrCreateInstance()->getCursorPos();
		m_CursorOffset[0] = CurMousePos[0] - m_PrevMousePos[0];
		m_CursorOffset[1] = CurMousePos[1] - m_PrevMousePos[1];
		m_PrevMousePos = CurMousePos;

		rotateX(m_CursorOffset[1] * m_Sensitivity);
		rotateY(m_CursorOffset[0] * m_Sensitivity);
	}
}

//**************************************************************************************************
//FUNCTION:
GLvoid CCube::__processMouseButtonRight(GLint vButton, GLint vAction, GLint vMods)
{
	if (vButton == GLFW_MOUSE_BUTTON_RIGHT && vAction == GLFW_PRESS)
	{
		m_ButtonRightPressed = true;
		m_PrevMousePos = CInputManager::getOrCreateInstance()->getCursorPos();
	}
	else if (vButton == GLFW_MOUSE_BUTTON_RIGHT && vAction == GLFW_RELEASE)
	{
		m_ButtonRightPressed = false;
	}
}
